//
//  MyCollectionTableViewCell.m
//  OpenYourEyes
//
//  Created by 沈振烨 on 15/8/14.
//  Copyright (c) 2015年 zhanglei. All rights reserved.
//

#import "MyCollectionTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "Header.h"

@interface MyCollectionTableViewCell ()

/** 图片*/
@property (nonatomic, strong, readwrite) UIImageView *AXImageView;


@end

@implementation MyCollectionTableViewCell


//程序里没用用Nib文件(XIB)时,用代码控制视图内容，需要调用initWithFrame去初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.AXImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 240)];
        [self.contentView addSubview:_AXImageView];
        //图片上的标题
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, self.bounds.size.width, 20)];
        _titleLabel.font = [UIFont fontWithName:@"ArialHebrew-Bold" size:20];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = [UIColor whiteColor];
        
        //图片上的类型和时间
        _categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 130, self.bounds.size.width, 30)];
        _categoryLabel.font = [UIFont fontWithName:@"ArialHebrew-Bold" size:15];
        _categoryLabel.textAlignment = NSTextAlignmentCenter;
        _categoryLabel.textColor = [UIColor whiteColor];
        
        //添加到视图上
        [self.contentView addSubview:self.AXImageView];
        
        //    [self.AXImageView addSubview:_view];
        [self.AXImageView addSubview:_titleLabel];
        [self.AXImageView addSubview:_categoryLabel];
        
    }
    return self;
}




#pragma mark - Setup Method
//- (void)setupImageView
//{
//    //决定了子视图的显示范围。具体的说，就是当取值为YES时，剪裁超出父视图范围的子视图部分；当取值为NO时，不剪裁子视图。默认值为NO。
////    self.clipsToBounds = YES;
//    
//    //设置图片的大小
//    self.AXImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
//    //UIViewContentModeScaleAspectFill也会证图片比例不变，但是是填充整个ImageView的，可能只有部分图片显示出来。
////    self.AXImageView.contentMode = UIViewContentModeScaleAspectFill;
////    self.AXImageView.clipsToBounds = NO;
//    
//    
//    //图片上的标题
//    _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, self.bounds.size.width, 20)];
//    _titleLabel.font = [UIFont fontWithName:@"ArialHebrew-Bold" size:20];
//    _titleLabel.textAlignment = NSTextAlignmentCenter;
//    _titleLabel.textColor = [UIColor whiteColor];
//    
//    //图片上的类型和时间
//    _categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 130, self.bounds.size.width, 30)];
//    _categoryLabel.font = [UIFont fontWithName:@"ArialHebrew-Bold" size:15];
//    _categoryLabel.textAlignment = NSTextAlignmentCenter;
//    _categoryLabel.textColor = [UIColor whiteColor];
//    
//    //添加到视图上
//    [self.contentView addSubview:self.AXImageView];
//    
////    [self.AXImageView addSubview:_view];
//    [self.AXImageView addSubview:_titleLabel];
//    [self.AXImageView addSubview:_categoryLabel];
//    
//}

- (void)addDownloadImageView
{
    _downloadView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 240)];
    _downloadView.backgroundColor = [UIColor lightGrayColor];
    _downloadView.alpha = 0.5;
    [self.contentView addSubview:_downloadView];
}


- (void)setModel:(DailyModel *)model
{
    _model = model;
    //解析图片数据
    [self.AXImageView sd_setImageWithURL:[NSURL URLWithString:model.coverForDetail]];
    
    
    
    //赋值
    self.titleLabel.text = model.title;
    NSString *timeStr = [NSString stringWithFormat:@"%.2ld'%ld\" ",model.duration/60,model.duration%60];
    
    //先拼接字符串，再把字符串#符号改变大小
    NSString *string = [NSString stringWithFormat:@"#%@  /  %@",model.category,timeStr];
    
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:string];
    // 设置文本的字体以及大小
    [attString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:16] range:NSMakeRange(0, 14)];
    
    self.categoryLabel.attributedText = attString;
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
